﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.gates {
    import Engine.Managers.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import org.aswing.ext.*;
    import Display.GateUI.*;
    import Modules.stats.types.*;

    public class AbstractGate implements IGate {

        public static const LOAD_TYPE_DYNAMIC:String = "dynamic";
        public static const LOAD_TYPE_STATIC:String = "static";
        public static const GS_VALUE:Number = 0.33;
        public static const SEND_GIFT_ITEM:String = "send_gift";
        public static const PRE_BUILD_GATE:String = "pre_build";
        public static const BUILD_GATE:String = "build";

        protected var m_keys:Object;
        protected var m_virals:Object;
        protected var m_targetObjectId:Number;
        protected var m_dialog:GenericDialog;
        private var m_unlockCB:Function = null;
        protected var m_unlockItemName:String;
        protected var m_cellFactory:GridListCellFactory;
        protected var m_loadType:String;
        protected var m_name:String;

        public function AbstractGate(_arg1:String){
            this.m_keys = new Object();
            this.m_virals = new Object();
            this.m_unlockItemName = _arg1;
        }
        public function set unlockCallback(_arg1:Function):void{
            this.m_unlockCB = _arg1;
        }
        public function set targetObjectId(_arg1:Number):void{
            this.m_targetObjectId = _arg1;
        }
        public function get loadType():String{
            return (this.m_loadType);
        }
        public function set loadType(_arg1:String):void{
            this.m_loadType = this.loadType;
        }
        public function loadFromXML(_arg1:XML):void{
            var _local2:XML;
            this.m_loadType = _arg1.@loadType;
            this.m_name = String(_arg1.@name);
            for each (_local2 in _arg1.key) {
                this.m_keys[_local2.@name] = _local2.@amount;
                this.m_virals[_local2.@name] = _local2.@viral.toString();
                if (this.m_virals[_local2.@name] == ""){
                    this.m_virals[_local2.@name] = AskFriendsDialog.REQUEST_BUILDABLE;
                };
            };
        }
        public function unlockGate():Boolean{
            if (this.checkForKeys() == true){
                this.takeKeys();
                if (this.m_unlockCB != null){
                    this.m_unlockCB();
                };
                if (((this.m_name) && (this.m_unlockItemName))){
                    StatsManager.sample(100, StatsKingdomType.GAME_ACTIONS, this.m_name, StatsPhylumType.VIRAL_UNLOCK, this.m_unlockItemName);
                };
                return (true);
            };
            return (false);
        }
        public function loadFromObject(_arg1:Object):void{
            var _local2:*;
            if ((((_arg1 == null)) || ((_arg1 == "")))){
                return;
            };
            this.m_name = String(_arg1.name);
            for (_local2 in _arg1.keys) {
                this.m_keys[_local2] = _arg1.keys[_local2];
                this.m_virals[_local2] = (((!((_arg1.virals == null))) && (!((_arg1.virals[_local2] == ""))))) ? _arg1.virals[_local2].toString() : AskFriendsDialog.REQUEST_BUILDABLE;
            };
            this.m_loadType = _arg1.loadType;
        }
        public function getKey(_arg1:String):int{
            if (this.m_keys.hasOwnProperty(_arg1)){
                return (this.m_keys[_arg1]);
            };
            return (0);
        }
        public function checkForKeys():Boolean{
            return (false);
        }
        protected function takeKeys():void{
        }
        public function get keyCount():int{
            var _local2:String;
            var _local1:int;
            for (_local2 in this.m_keys) {
                _local1++;
            };
            return (_local1);
        }
        public function getKeyArray():Array{
            var _local2:String;
            var _local1:Array = new Array();
            for (_local2 in this.m_keys) {
                _local1.push(_local2);
            };
            return (_local1);
        }
        public function getRequirementString():String{
            return (null);
        }
        public function buyAll():void{
            var _local3:String;
            var _local4:Item;
            var _local5:uint;
            var _local6:uint;
            var _local7:int;
            var _local8:uint;
            var _local9:String;
            var _local1:uint;
            var _local2:Dictionary = new Dictionary();
            for (_local3 in this.m_keys) {
                _local4 = Global.gameSettings.getItemByName(_local3);
                _local5 = Global.player.inventory.getItemCount(_local4);
                _local6 = this.m_keys[_local3];
                _local7 = Math.max(0, (_local6 - _local5));
                _local2[_local3] = _local7;
                _local8 = (_local2[_local3] * _local4.cash);
                _local1 = (_local1 + _local8);
            };
            if (Global.player.canBuyCash(_local1)){
                for (_local9 in this.m_keys) {
                    if (_local2[_local9] > 0){
                        _local4 = Global.gameSettings.getItemByName(_local9);
                        GameTransactionManager.addTransaction(new TBuyItem(_local4.name, _local2[_local9], this.m_unlockItemName));
                    };
                };
                this.unlockGate();
                this.m_dialog.close();
                this.m_dialog = null;
            };
            _local2 = null;
        }
        public function displayGate(_arg1:String=null, _arg2:String=null):void{
        }
        protected function updateItemArrowState():void{
            var _local2:ConstructionSite;
            var _local1:Array = Global.world.getObjectsByClass(ConstructionSite);
            for each (_local2 in _local1) {
                _local2.forceUpdateArrow();
            };
        }

    }
}//package Classes.gates 
